#include "stdafx.h"
#include "XConfigAttrImpl.h"

#include "XStrUtil.h"

IMPLEMENT_SKIN_CLASS(CXConfigAttrImpl);

CXConfigAttrImpl::CXConfigAttrImpl()
{
    m_pAttr = NULL;
}

CXConfigAttrImpl::~CXConfigAttrImpl()
{
    m_pAttr = NULL;
}

// IXConfigAttr
HRESULT CXConfigAttrImpl::GetName(OUT BSTR* pbstrName)
{
    if(m_pAttr == NULL)
        return E_FAIL;

    const char* pName = m_pAttr->Name();
    if(pName == NULL)
        return E_FAIL;

    XString strName = XStrUtil::Utf8ToStr(pName);
    if(::SysReAllocString(pbstrName, strName.GetData()))
        return S_OK;
    else
        return E_FAIL;
}

HRESULT CXConfigAttrImpl::GetValue(OUT BSTR* pbstrValue)
{
    if(m_pAttr == NULL)
        return E_FAIL;

    const char* pValue = m_pAttr->Value();
    if(pValue == NULL)
        return E_FAIL;

    XString strValue = XStrUtil::Utf8ToStr(pValue);
    if(::SysReAllocString(pbstrValue, strValue.GetData()))
        return S_OK;
    else
        return E_FAIL;
}

// CXConfigAttrImpl
void CXConfigAttrImpl::put_Attr(TiXmlAttribute* pAttr)
{
    m_pAttr = pAttr;
}